package org.tc.feign.storefront;

import org.gdtc.storefront.entity.Bannerpicture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tc.feign.service.FeignBannerService;

import java.util.List;

@RestController
@RequestMapping("/FeignBannerController")
@CrossOrigin(origins = {"*"}, methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.OPTIONS}, allowCredentials = "true")
public class FeignBannerController {
    @Autowired
    private FeignBannerService feignBannerService;

    /**
     * 查询所有轮播图
     *
     * @return
     */
    @RequestMapping("/QueryAllBanner")
    @ResponseBody
    public List<Bannerpicture> QueryAllBanner(@RequestBody Integer storeid) {
        List<Bannerpicture> list = feignBannerService.selectAll(storeid);
        return list;
    }

    /**
     * 删除轮播
     *
     * @param id 轮播ID
     * @return
     */
    @RequestMapping("/DelBanner")
    @ResponseBody
    public int DelBanner(@RequestBody Integer id) {
        int count = feignBannerService.deleteByPrimaryKey(id);
        return count;
    }

    /**
     * 添加轮播图到数据库并上传到OSS
     *
     * @param bannerpicture
     * @return
     */
    @RequestMapping("/InsBanner")
    @ResponseBody
    public int InsBanner(@RequestBody Bannerpicture bannerpicture) {
        int count = feignBannerService.InaBanner(bannerpicture);
        return count;
    }

    /**
     * 修改轮播图状态 state=1启用 state=0禁用
     *
     * @param state 状态
     * @param id    Banner ID
     * @return
     */
    @RequestMapping("/UpdState")
    @ResponseBody
    public int UpdState(Integer state, Integer id) {
        int count = feignBannerService.UpdState(state, id);
        return count;
    }
}
